using UnityEngine;
using System.Collections;
using System;

public class PowerUp : MonoBehaviour {

	public int Type = 1; //1 = tir *2, 2 smartBomb,3 temps * 2, 4 bouclier
	public int shootTime = 10;
	public int TimeMult2Time = 10;
	public int shieldTime = 10;

	public Texture Power;
	public Texture Bomb;
	public Texture Time;
	public Texture shield;


	void OnTriggerEnter(Collider other)
	{
		if (other.tag == "Player")
		{
			switch (Type)
			{
				case 1 :
					other.GetComponent<player>().acc_powerUp = Type;
					other.GetComponent<player>().acc_PowerUpTime = new TimeSpan(0, 0, shootTime);
					GameObject.FindGameObjectWithTag("PowerUp_Text").GetComponent<PowerUpinfo>().Power();
					Destroy(this.gameObject);
					other.SendMessage("OnPowerUp");
					break;
				case 2:
					GameObject.FindGameObjectWithTag("PowerUp_Text").GetComponent<PowerUpinfo>().bomb();
					if (other.GetComponent<player>().addBomb())
					{
						Destroy(this.gameObject);
					}
					other.SendMessage("OnBombGrabbed");
					break;
				case 3 :
					other.GetComponent<player>().acc_powerUp = Type;
					other.GetComponent<player>().acc_PowerUpTime = new TimeSpan(0, 0, TimeMult2Time);
					GameObject.FindGameObjectWithTag("PowerUp_Text").GetComponent<PowerUpinfo>().Time();
					Destroy(this.gameObject);
					other.SendMessage("OnPowerUp");
					break;
				case 4 :
					other.GetComponent<player>().acc_powerUp = Type;
					other.GetComponent<player>().acc_PowerUpTime = new TimeSpan(0, 0, shieldTime);
					GameObject.FindGameObjectWithTag("PowerUp_Text").GetComponent<PowerUpinfo>().shield();
					Destroy(this.gameObject);
					other.SendMessage("OnPowerUp");
					break;
			}
		}
	}



	// Update is called once per frame
	void Update () {
		switch (Type)
		{
			case 1:
				renderer.materials[0].SetTexture("_MainTex", Power);
				break;
			case 2:
				renderer.materials[0].SetTexture("_MainTex", Bomb);
				break;
			case 3:
				renderer.materials[0].SetTexture("_MainTex", Time);
				break;
			case 4:
				renderer.materials[0].SetTexture("_MainTex", shield);
				break;
		}
	}
}
